﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace QLHXNK.DataAccess
{
    class Import_Note_DetailData
    {
        #region --------------------------------------------Thêm, Xoá, Sửa-----------------------------------------
        //Thêm:
        public static int Insert(int import_note_id, int item_id, String quantity, String fob_usd, String fob_eur, String cif_usd, String cif_eur, String kr_fee, String hk_fee, String ita_fee, String tl_fee, String other_country_fee, String ut_fee, String vat_fee, String tax_fee, String other_fee, String net1, String net2, String selling_price, String profit1, String profit2)
        {
            String strSQL = String.Format("INSERT INTO Import_Note_Detail ( import_note_id, item_id, quantity, fob_usd, fob_eur, cif_usd, cif_eur, kr_fee, hk_fee, ita_fee, tl_fee, other_country_fee, ut_fee, vat_fee, tax_fee, other_fee, net1, net2, selling_price, profit1, profit2) VALUES ({0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, {13}, {14}, {15}, {16}, {17}, {18}, {18}, {20})", import_note_id, item_id, (quantity == "") ? "NULL" : quantity, (fob_usd == "") ? "NULL" : fob_usd, (fob_eur == "") ? "NULL" : fob_eur, (cif_usd == "") ? "NULL" : cif_usd, (cif_eur == "") ? "NULL" : cif_eur, (kr_fee == "") ? "NULL" : kr_fee, (hk_fee == "") ? "NULL" : hk_fee, (ita_fee == "") ? "NULL" : ita_fee, (tl_fee == "") ? "NULL" : tl_fee, (other_country_fee == "") ? "NULL" : other_country_fee, (ut_fee == "") ? "NULL" : ut_fee, (vat_fee == "") ? "NULL" : vat_fee, (tax_fee == "") ? "NULL" : tax_fee, (other_fee == "") ? "NULL" : other_fee, (net1 == "") ? "NULL" : net1, (net2 == "") ? "NULL" : net2, (selling_price == "") ? "NULL" : selling_price, (profit1 == "") ? "NULL" : profit1, (profit2 == "") ? "NULL" : profit2);
            return MyDataTransfer.executeNonQueryCommand(strSQL);
        }

        //Xóa://////////////////////////////
        public static int Delete(int ID)
        {
            String strSQL = String.Format("DELETE FROM Import_Note_Detail WHERE ID = {0}", ID);
            return MyDataTransfer.executeNonQueryCommand(strSQL);
        }

        public static int Delete_In_Import_Note(int Import_Note_ID)
        {
            String strSQL = String.Format("DELETE FROM Import_Note_Detail WHERE import_note_id = {0}", Import_Note_ID);
            return MyDataTransfer.executeNonQueryCommand(strSQL);
        }
        //Sửa:
        public static int Update(int ID, int import_note_id, int item_id, String quantity, String fob_usd, String fob_eur, String cif_usd, String cif_eur, String kr_fee, String hk_fee, String ita_fee, String tl_fee, String other_country_fee, String ut_fee, String vat_fee, String tax_fee, String other_fee, String net1, String net2, String selling_price, String profit1, String profit2)
        {
            String strSQL = String.Format("UPDATE  Import_Note_Detail SET import_note_id = {0}, item_id = {1}, quantity = {2}, fob_usd = {3}, fob_eur = {4}, cif_usd = {5}, cif_eur = {6}, kr_fee = {7}, hk_fee = {8}, ita_fee = {9}, tl_fee = {10}, other_country_fee = {11}, ut_fee = {12}, vat_fee = {13}, tax_fee = {14}, other_fee = {15}, net1 = {16}, net2 = {17}, selling_price = {18}, profit1 = {19}, profit2 = {20} WHERE ID = {21}", import_note_id, item_id, (quantity == "") ? "NULL" : quantity, (fob_usd == "") ? "NULL" : fob_usd, (fob_eur == "") ? "NULL" : fob_eur, (cif_usd == "") ? "NULL" : cif_usd, (cif_eur == "") ? "NULL" : cif_eur, (kr_fee == "") ? "NULL" : kr_fee, (hk_fee == "") ? "NULL" : hk_fee, (ita_fee == "") ? "NULL" : ita_fee, (tl_fee == "") ? "NULL" : tl_fee, (other_country_fee == "") ? "NULL" : other_country_fee, (ut_fee == "") ? "NULL" : ut_fee, (vat_fee == "") ? "NULL" : vat_fee, (tax_fee == "") ? "NULL" : tax_fee, (other_fee == "") ? "NULL" : other_fee, (net1 == "") ? "NULL" : net1, (net2 == "") ? "NULL" : net2, (selling_price == "") ? "NULL" : selling_price, (profit1 == "") ? "NULL" : profit1, (profit2 == "") ? "NULL" : profit2, ID);

            return MyDataTransfer.executeNonQueryCommand(strSQL);
        }
        #endregion

        #region -----------------------------------------Lấy danh sách----------------------------------
        public static DataTable getImport_Note_DetailList(String strSQL)
        {
            if (strSQL == "") //get all fields
                strSQL = "SELECT * FROM Import_Note_Detail";

            return MyDataTransfer.executeQueryCommand(strSQL);
        }
        #endregion
    }
}
